package com.xnyzc.lhy.mis.controller.cmsapi.price;

import com.xnyzc.lhy.common.entity.Rv;
import com.xnyzc.lhy.common.penum.EErrorCode;
import com.xnyzc.lhy.common.util.CheckUtil;
import com.xnyzc.lhy.mis.entity.param.cms.price.AddPriceParam;
import com.xnyzc.lhy.mis.entity.param.cms.price.NewBillRulesParam;
import com.xnyzc.lhy.mis.entity.param.cms.price.PriceParam;
import com.xnyzc.lhy.mis.entity.system.*;
import com.xnyzc.lhy.mis.service.cms.price.PriceTemplateService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * 价格模板相关
 *
 * @Author: wangshuo
 * @Date: 2019-08-07 14:11
 */
@RestController
@RequestMapping("/cmsapi/price")
public class PriceTemplateController {

    @Autowired
    private PriceTemplateService priceTemplateService;

/**
 * 获取多机场多火车站列表
 */
    @ApiOperation(value = "获取多机场多火车站列表",notes = "获取多机场多火车站列表")
    @PostMapping(value = "/getStationList")
    public Rv getStationList(@ApiParam(name = "priceParam", value = "获取多机场多火车站列表") @RequestBody PriceParam priceParam){
        return Rv.wrap(priceTemplateService.getStationList(priceParam));
    }

    /**
     * 新增或修改计费规则组
     *
     * @return
     */
    @ApiOperation(value = "新增或修改计费规则组", notes = "新增或修改计费规则组")
    @PostMapping(value = "/addOrUpdateRuleGroup")
    public Rv addOrUpdateRuleGroup(
            @ApiParam(name = "priceParam", value = "新增或修改计费规则组") @RequestBody OaSysBillRuleGroup ruleGroup
    ) {
        return Rv.wrap(priceTemplateService.addOrUpdateRuleGroup(ruleGroup));
    }

    /**
     * 新增或修改城市区规则组
     * @return
     */
    @ApiOperation(value = "新增或修改城市区规则组",notes = "新增或修改城市区规则组")
    @PostMapping(value = "/addOrUpdateCityProperRuleGroup")
    public Rv addOrUpdateCityProperRuleGroup(
            @ApiParam(name = "priceParam",value = "新增或修改城市区规则组") @RequestBody OaSysCityProperRuleGroup ruleGroup)
    {
        return Rv.wrap(priceTemplateService.addOrUpdateCityProperRuleGroup(ruleGroup));
    }
    /**
     * 获取计费规则组列表
     *
     * @return
     */
    @ApiOperation(value = "获取计费规则组列表", notes = "获取计费规则组列表")
    @PostMapping(value = "/getRuleGroup")
    public Rv getRuleGroup(
            @ApiParam(name = "priceParam", value = "获取计费规则组列表") @RequestBody PriceParam priceParam
    ) {
        return Rv.wrap(priceTemplateService.getRuleGroup(priceParam));
    }

    /**
     * 获取城市区规则组列表
     *
     * @return
     */
    @ApiOperation(value = "获取城市区规则组列表", notes = "获取城市区规则组列表")
    @PostMapping(value = "/getCityProperRuleGroup")
    public Rv getCityProperRuleGroup(
            @ApiParam(name = "priceParam", value = "获取城市区规则组列表") @RequestBody PriceParam priceParam
    ) {
        return Rv.wrap(priceTemplateService.getCityProperRuleGroup(priceParam));
    }

    /**
     * 新增或修改价格模板
     *
     * @return
     */
    @ApiOperation(value = "新增或修改价格模板", notes = "新增或修改价格模板")
    @PostMapping(value = "/addOrUpdatePriceTemplate")
    public Rv addOrUpdatePriceTemplate(
            @ApiParam(name = "priceParam", value = "新增或修改价格模板") @RequestBody AddPriceParam param
    ) {
        return Rv.wrap(priceTemplateService.addOrUpdatePriceTemplate(param));
    }

    /**
     * 获取 新的价格模详情
     *
     * @return
     */
    @ApiOperation(value = "获取新的价格模详情", notes = "获取新的价格模详情")
    @PostMapping(value = "/getNewPriceTemplateDetails")
    public Rv getNewPriceTemplateDetails(
            @ApiParam(name = "priceParam", value = "获取新的价格模详情") @RequestBody PriceParam priceParam
    ) {
        return Rv.wrap(priceTemplateService.getNewPriceTemplateDetails(priceParam));
    }

    /**
     * 新增或修改城市区规则
     *
     * @return
     */
    @ApiOperation(value = "新增或修改城市区规则", notes = "新增或修改城市区规则")
    @PostMapping(value = "/addOrUpdateCityProperRule")
    public Rv addOrUpdateCityProperRule(
            @ApiParam(name = "priceParam", value = "新增或修改城市区规则") @RequestBody AddPriceParam param
    ) {
        return Rv.wrap(priceTemplateService.addOrUpdateCityProperRule(param));
    }

    /**
     * 获取城市区规则详情
     *
     * @return
     */
    @ApiOperation(value = "获取城市区规则详情", notes = "获取城市区规则详情")
    @PostMapping(value = "/getCityProperRuleDetails")
    public Rv getCityProperRuleDetails(
            @ApiParam(name = "priceParam", value = "获取城市区规则详情") @RequestBody PriceParam priceParam
    ) {
        return Rv.wrap(priceTemplateService.getCityProperRuleDetails(priceParam));
    }

    /**
     * 新增或修改平台时间规则
     *
     * @return
     */
    @ApiOperation(value = "新增或修改平台时间规则", notes = "新增或修改平台时间规则")
    @PostMapping(value = "/addOrUpdatePlatformTimeRule")
    public Rv addOrUpdatePlatformTimeRule(
            @ApiParam(name = "priceParam", value = "新增或修改平台时间规则") @RequestBody AddPriceParam param
    ) {
        return Rv.wrap(priceTemplateService.addOrUpdatePlatformTimeRule(param));
    }

    /**
     * 获取平台时间规则详情
     *
     * @return
     */
    @ApiOperation(value = "获取平台时间规则详情", notes = "获取平台时间规则详情")
    @PostMapping(value = "/getPlatformTimeRuleDetails")
    public Rv getPlatformTimeRuleDetails(
            @ApiParam(name = "priceParam", value = "获取平台时间规则详情") @RequestBody PriceParam priceParam
    ) {
        return Rv.wrap(priceTemplateService.getPlatformTimeRuleDetails(priceParam));
    }
    /**
     * 价格模板启用
     *
     * @return
     */
    @ApiOperation(value = "价格模板启用", notes = "价格模板启用")
    @PostMapping(value = "/disablePrice")
    public Rv disablePrice(
            @ApiParam(name = "priceParam", value = "价格模板启用") @RequestBody PriceParam priceParam
    ) {
        return Rv.wrap(priceTemplateService.disablePrice(priceParam));
    }
    @ApiOperation(value = "调整表结构", notes = "合并oa_sys_bill_rule（计价规则），oa_sys_bill_special_time_rule（特殊时间规则），oa_sys_bill_special_date_rule（特殊日期） 三个表")
    @PostMapping(value = "/merageTables")
    public Rv merageTables(){
        //TODO 合并
        priceTemplateService.merageTables();
        return Rv.wrap(EErrorCode.success);
    }
    @ApiOperation(value = "新版本费用规则查询接口", notes = "新版本费用规则接口")
    @PostMapping(value = "/getNewPriceDetails")
    public Rv getNewPriceDetails(
            @ApiParam(name = "",value = ""
            )@RequestBody PriceParam priceParam ){
        return priceTemplateService.getNewPriceDetails(priceParam);
    }

    @ApiOperation(value = "新版本费用新增规则接口", notes = "新版本费用规则接口")
    @PostMapping(value = "/addNewPriceDetails")
    public Rv addNewPriceDetails(
            @ApiParam(name = "",value = "")
            @RequestBody NewBillRulesParam billRulesParam ){
        //参数校验
        Integer areaId = billRulesParam.getAreaId();
        Integer channel = billRulesParam.getChannel();
        Integer callType = billRulesParam.getCallType();
        String retRV="";
        if (areaId==null){
            retRV+="区域id";
        }
        if (channel==null){
            retRV+=" 渠道";
        }
        if (callType == null) {
            retRV+=" 呼叫类型";
        }
        if (CheckUtil.strIsNotEmpty(retRV)){
            return Rv.wrap(EErrorCode.missingArg,retRV);
        }
        priceTemplateService.addNewPriceDetails(billRulesParam);
        return Rv.wrap(EErrorCode.success);
    }

    @ApiOperation(value = "拒绝服务区域新旧字段转换接口", notes = "拒绝服务区域新旧字段转换接口")
    @PostMapping(value = "/exchangeRefuseArea")
    public Rv exchangeRefuseArea(){
        priceTemplateService.exchangeRefuseArea();
        return Rv.wrap(EErrorCode.success);
    }


}
